import axios from 'axios'
import { ElMessage } from 'element-plus'

const instance = axios.create({
    baseURL: '/api',
    timeout: 10000
})
// 请求拦截
instance.interceptors.request.use(config => {
    //   config.headers = {
    //     ...config.headers,
    //     Authorization: "Bearer " + store.state.user.token || ''
    //   }
    return config
}, err => {
    Promise.reject(err)
})
// 响应拦截
instance.interceptors.response.use(res => {
    if (res.data.code === 0) {
        ElMessage({
            message: res.data.msg,
            type: 'success'
        })
    } else {
        // console.log(res);

        ElMessage({
            message: res.data,
            type: 'warning'
        })
    }
    return res
}, err => {
    Promise.reject(err)
})
export default instance
